import torch 
from scipy import signal
import numpy as np 

if __name__ == "__main__":
    src_data = torch.load("./src_data_raw.pkl")
    # src_data = src_data[:100]
    src_data = src_data[:, :375, :]
    print(src_data.shape)
    src_data = src_data - torch.mean(src_data, dim=0)
    print(src_data.shape)

    detrend_data = signal.detrend(src_data, axis=0)
    print(detrend_data.shape)

  
    wn = 2 * 80 / 1000
    b, a = signal.butter(6, wn, "lowpass")
    filted_data = signal.filtfilt(b, a, detrend_data, axis=0)
    print(filted_data.shape)
    data = filted_data.astype(np.float32).copy()

    # print(data)

    data = torch.tensor(data)
    torch.save(data, "./src_data_0711.pkl")

    # # print(data.shape)
    # print(data[:2])
    # data = data.copy()
    # data = torch.tensor(data, dtype=torch.float32)

    # data = data.copy()
    # data = torch.tensor(data, dtype=torch.float32)
    # print(data.shape)
    # print(((data - torch.mean(data)) / torch.std(data))[0])
    
    # print(type(data))
    # torch.save(data, "./src_data_raw滤波.pkl")